package oxi.bigu.api;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import oxi.bigu.business.Caronado;
import oxi.bigu.business.CaronadoController;
import oxi.bigu.business.Location;
import oxi.bigu.business.LocationController;

@Path("/carona")
@Produces(MediaType.APPLICATION_JSON)
@Component
public class CaronaResources {
	
	@Autowired
	private CaronadoController caronadoController;
	@Autowired
	private LocationController locationController;

	@GET
	public List<Caronado> getCaroneiros(){
		return caronadoController.searchCaronados();
	}
	
	@POST
	@Path("/caroneiro")
	public Integer postCaroneiro(CaroneiroDto dto){
		ModelMapper model = new ModelMapper();
		Caronado caronado = model.map(dto, Caronado.class);
		caronadoController.createCaronado(caronado);
		return caronado.getId();
	}
	
	@POST
	@Path("/location")
	public void postLocation(LocationDto dto){
		ModelMapper model = new ModelMapper();
		Location location = model.map(dto, Location.class);
		System.out.println(location);
		locationController.createLocation(location);
	}

}
